<template>
  <el-dialog
      v-model="toolEditWinDialog"
      title="编辑计划"
      width="50%">
    <template #default>
      <el-form :model="editTool" label-width="auto">
        <el-form-item label="类型编码">
          <el-input v-model="editTool.toolTypeCode"/>
        </el-form-item>
        <el-form-item label="类型名称">
          <el-input v-model="editTool.toolTypeName"/>
        </el-form-item>
        <el-form-item label="是否编码管理">
          <el-select style="width: 100px" v-model="editTool.codeManage">
            <el-option :value="1" label="是"/>
            <el-option :value="2" label="否"/>
          </el-select>
        </el-form-item>
        <el-form-item label="保养维护类型">
          <el-radio-group v-model="editTool.maintainType">
            <el-radio value="定期维护" size="large">定期维护</el-radio>
            <el-radio value="按使用次数维护" size="large">按使用次数维护</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="保养周期">
          <el-input v-model="editTool.serviceInterval"/>
        </el-form-item>
        <el-form-item label="备注">
          <el-input v-model="editTool.toolTypeNotes"/>
        </el-form-item>
      </el-form>
    </template>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="cancel">取消</el-button>
        <el-button type="primary" @click="editToolTypeSubmit">
          提交
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup>

import {ref, watch} from "vue";
import ledgerRequest from "@/api/ledger.js";
import {ElMessage} from "element-plus";
import maintainPlanRequest from "@/api/maintainPlan.js";
import toolsTypeRequest from "@/api/toolsType.js";
const props = defineProps(['toolTypeId']);
const emits = defineEmits(['editComplate']);
let toolEditWinDialog = ref(false);
let editTool = ref({});

function cancel(){
  editTool = ref({});
  toolEditWinDialog.value =false;
}
function editToolTypeSubmit(){
  toolsTypeRequest.updateType(editTool.value,res=>{
    if (res.code == 200){
      ElMessage({
        type:"success",
        message:"修改成功"
      });
      cancel()
      emits('editComplate');
    }else {
      ElMessage({
        type:"warning",
        message:"修改失败"
      })
    }
  })
}

function loadToolTypeById(){
  toolsTypeRequest.selectById(props.toolTypeId,res=>{
    if (res.data){
      editTool.value =res.data;
      toolEditWinDialog.value = true;
    }
  })
}

watch(()=>props.toolTypeId,()=>{
  if(props.toolTypeId){
    loadToolTypeById();
  }
});


</script>

<style scoped>

</style>